<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>UserGroupBusiness.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #000000; background-color: #ffffff; font-family: Monospaced}
pre {color: #000000; background-color: #ffffff; font-family: Monospaced}
table {color: #000000; background-color: #e9e8e2; font-family: Monospaced}
.ST0 {color: #969696; font-family: Monospaced; font-weight: bold}
.comment {color: #969696}
.line-number {background-color: #e9e8e2}
.character {color: #ce7b00}
.keyword-directive {color: #0000e6}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">C:\GoogleCode\bari\Bari\src\java\dk\jsh\itdiplom\dbsw\bari\business\UserGroupBusiness.java</td></tr></table>
<pre>
<span class="line-number"> 1</span> <span class="keyword-directive">package</span> dk.jsh.itdiplom.dbsw.bari.business;
<span class="line-number"> 2</span> 
<span class="line-number"> 3</span> <span class="keyword-directive">import</span> dk.jsh.itdiplom.dbsw.bari.domain.BariUser;
<span class="line-number"> 4</span> <span class="keyword-directive">import</span> dk.jsh.itdiplom.dbsw.bari.domain.Product;
<span class="line-number"> 5</span> <span class="keyword-directive">import</span> dk.jsh.itdiplom.dbsw.bari.util.HibernateUtil;
<span class="line-number"> 6</span> <span class="keyword-directive">import</span> java.util.ArrayList;
<span class="line-number"> 7</span> <span class="keyword-directive">import</span> java.util.List;
<span class="line-number"> 8</span> <span class="keyword-directive">import</span> org.hibernate.Query;
<span class="line-number"> 9</span> <span class="keyword-directive">import</span> org.hibernate.Session;
<span class="line-number">10</span> 
<span class="line-number">11</span> <span class="comment">/**</span>
<span class="line-number">12</span> <span class="comment"> * </span><span class="comment">Business</span> <span class="comment">me</span><span class="comment">tods</span> <span class="comment">for</span> <span class="comment">UserGroup</span><span class="comment">.</span>
<span class="line-number">13</span> <span class="comment"> *</span>
<span class="line-number">14</span> <span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">Jan</span> <span class="comment">S</span><span class="comment">.</span> <span class="comment">Hansen</span>
<span class="line-number">15</span>  <span class="comment">*/</span>
<span class="line-number">16</span> <span class="keyword-directive">public</span> <span class="keyword-directive">class</span> UserGroupBusiness {
<span class="line-number">17</span> 
<span class="line-number">18</span>     <span class="comment">/**</span>
<span class="line-number">19</span> <span class="comment">     * </span><span class="comment">Get</span> <span class="comment">all</span> <span class="comment">Products</span> <span class="comment">a</span> <span class="comment">given</span> <span class="comment">bariUser</span> <span class="comment">can</span> <span class="comment">access</span><span class="comment">.</span>
<span class="line-number">20</span>  <span class="comment">    *</span>
<span class="line-number">21</span> <span class="comment">     * </span><span class="ST0">@param</span> <span class="comment">bariCase</span> <span class="comment">BariCase</span><span class="comment">.</span>
<span class="line-number">22</span> <span class="comment">     * </span><span class="ST0">@return</span> <span class="comment">a</span> <span class="comment">List</span> <span class="comment">of</span> <span class="comment">DiscussionMessage</span> <span class="comment">objects</span><span class="comment">.</span>
<span class="line-number">23</span>      <span class="comment">*/</span>
<span class="line-number">24</span>     <span class="keyword-directive">public</span> <span class="keyword-directive">static</span> List&lt;Product&gt; getAllDiscussionMessages(
<span class="line-number">25</span>             BariUser bariUser) {
<span class="line-number">26</span>         List&lt;Product&gt; products =
<span class="line-number">27</span>                 <span class="keyword-directive">new</span> ArrayList&lt;Product&gt;();
<span class="line-number">28</span>         Session session = HibernateUtil.getSessionFactory().openSession();
<span class="line-number">29</span>         String hql = <span class="character">&quot;</span><span class="character">select product from </span><span class="character">&quot;</span>
<span class="line-number">30</span>                 + <span class="character">&quot;</span><span class="character">dk.jsh.itdiplom.dbsw.bari.domain.Product product, </span><span class="character">&quot;</span>
<span class="line-number">31</span>                 + <span class="character">&quot;</span><span class="character">dk.jsh.itdiplom.dbsw.bari.domain.UserGroup userGroup </span><span class="character">&quot;</span>
<span class="line-number">32</span>                 + <span class="character">&quot;</span><span class="character">where userGroup.bariUser.id = :userid and </span><span class="character">&quot;</span>
<span class="line-number">33</span>                 + <span class="character">&quot;</span><span class="character">product.id = userGroup.product.id </span><span class="character">&quot;</span>
<span class="line-number">34</span>                 + <span class="character">&quot;</span><span class="character">order by product.name</span><span class="character">&quot;</span>;
<span class="line-number">35</span>         Query query = session.createQuery(hql);
<span class="line-number">36</span>         query.setString(<span class="character">&quot;</span><span class="character">userid</span><span class="character">&quot;</span>, bariUser.getId().toString());
<span class="line-number">37</span>         products = query.list();
<span class="line-number">38</span>         session.close();
<span class="line-number">39</span>         <span class="keyword-directive">return</span> products;
<span class="line-number">40</span>     }
<span class="line-number">41</span> }
<span class="line-number">42</span> 
</pre></body>
</html>
